/*
 * @Author: 肖思汗 
 * @Date: 2025-11-03 17:30:34 
 * @Last Modified by:   xiaosihan 
 * @Last Modified time: 2025-11-03 17:30:34 
 */

import ServiceBase from "./ServiceBase";
import os from "os";
import numeral from "numeral";
import express from 'express';

//初始化
class UtilsService extends ServiceBase {

    constructor(req: express.Request = {} as express.Request, res: express.Response = {} as express.Response) {
        super(req, res);
    }

    // 获取 ping
    get_ping = () => {
        try {
            return {
                buildTime: process.env.BUILD_TIME,
                cup: os.cpus().length, // 获取CPU信息  
                totalmem: numeral(os.totalmem()).format('0.0b'), // 总内存
                freemem: numeral(os.freemem()).format('0.0b'),// 空闲内存
            };
        } catch (error) {
            console.error("获取系统信息失败:", error);
            throw new Error(`获取系统信息失败: ${error instanceof Error ? error.message : String(error)}`);
        }
    };
}

const utilsService = new UtilsService();

export default utilsService;
